<%--
  Created by IntelliJ IDEA.
  User: 杨飞龙
  Date: 2020/5/29
  Time: 17:38
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML>
<html>
<head>
    <!-- 设置页面的 基本路径，页面所有资源引入和页面的跳转全部基于 base路径 -->
    <base href="<%=basePath%>">

    <link rel="stylesheet" type="text/css" href="lib/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="lib/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="lib/z-tree/css/zTreeStyle/zTreeStyle.css">


    <%--js--%>
    <script type="text/javascript" src="lib/easyui/jquery.min.js">
    </script>
    <script type="text/javascript" src="lib/easyui/jquery.easyui.min.js">
    </script>
    <script type="text/javascript" src="lib/z-tree/js/jquery.ztree.all.js"></script>
    <script type="text/javascript" src="lib/easyui/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="lib/jquery.serializejson/jquery.serializejson.min.js"></script>
</head>
<body>

<%--添加弹框--%>
<div id="addWindow" class="easyui-window" title="添加主持人" style="width:600px;height:400px"
     data-options="modal:true,closed:true">
    <form id="hostForm" action="host/insert.do" method="post">
        <div style="padding: 10px 50px">
            <input required class="easyui-textbox" prompt="请输入用户名"
                   data-options="missingMessage:'用户名不能为空',label:'姓名：'"
                   style="width:100%;height:30px;padding:10px" name="hname">
        </div>
        <div style="padding: 10px 50px">
            <input required class="easyui-passwordbox" prompt="请输入密码" iconWidth="28"
                   style="width:100%;height:30px;padding:10px"
                   data-options="showEye:false,missingMessage:'密码不能为空',label:'密码：'"
                   name="hpwd">
        </div>
        <%--   <div style="padding: 10px 50px">
                   <input required class="easyui-passwordbox" prompt="请再次输入密码" iconWidth="28"
                      style="width:100%;height:30px;padding:10px"
                      data-options="showEye:false,missingMessage:'密码不能为空',label:'确认密码：'" validType="equalTo['#hpwd']" invalidMessage="两次输入密码不匹配"
                      name="pwd2">
           </div>--%>
        <div style="padding: 10px 50px">
            <input required class="easyui-textbox" prompt="请输入电话" iconWidth="28"
                   style="width:100%;height:30px;padding:10px"
                   data-options="label:'电话：'"
                   name="hphone">
        </div>
        <%--  <div style="padding: 10px 50px">
              <input  required class="easyui-datebox" name="starttime" data-options="label:'注册时间：'"
                           style="width:100%;height:30px;padding:10px">
          </div>--%>

        <div style="padding: 15px 50px;text-align: center">
            <a onclick="insertHost()" href="javascript:void(0)" class="easyui-linkbutton">提交</a>
        </div>

    </form>
</div>

<%--权限设置窗口--%>
<div id="hostPowerWindow" class="easyui-window" title="权限设置" style="width:500px;height:500px"
     data-options="modal:true,closed:true">
    <form id="hostPowerForm" action="hostPower/hostPowerSet.do" method="post">
        <%--权限设置的id--%>
        <input type="hidden" name="hostids" id="hostid">
        <div style="padding: 10px 50px;">
            <label style="margin: 0 10px">星推荐：</label>
            <input class="easyui-radiobutton" labelWidth="40px" labelPosition="after" name="hpstar" value="1"
                   label="是">
            <input class="easyui-radiobutton" labelWidth="40px" labelPosition="after" name="hpstar" value="0"
                   label="否">
        </div>

        <div style="padding: 10px 10px">
            <label style="margin: 0 10px">星推荐有效期：</label>
            <input class="easyui-datebox" name="hpstartBegindate" prompt="开始时间"
                   style="width:30%;height:30px;padding:10px">
            --
            <input class="easyui-datebox" name="hpstarEnddate" prompt="结束时间"
                   style="width:30%;height:30px;padding:10px">
        </div>

        <div style="padding: 10px 40px;">
            <label style="margin: 0 10px">自添订单：</label>
            <input class="easyui-radiobutton" labelWidth="40px" labelPosition="after" name="hpOrderPower" value="1"
                   label="允许">
            <input class="easyui-radiobutton" labelWidth="60px" labelPosition="after" name="hpOrderPower" value="0"
                   label="不允许">
        </div>

        <div style="padding: 10px 30px">
            <label style="margin: 0 10px">星推荐时间：</label>
            <input class="easyui-timespinner" showSeconds="true" name="hpstarBegintime" value="08:00:00" prompt="开始时间"
                   style="width:30%;height:30px;padding:10px">
            --
            <input class="easyui-timespinner" name="hpstarEndtime" showSeconds="true" value="21:00:00" prompt="结束时间"
                   style="width:30%;height:30px;padding:10px">
        </div>

        <div style="padding: 10px 70px;">
            <label style="margin: 0 10px">折扣：</label>
            <input class="easyui-textbox" style="width: 25%" name="hpdiscount">
        </div>

        <div style="padding: 10px 40px">
            <label style="margin: 0 10px">折扣周期：</label>
            <input class="easyui-datebox" name="hpDisStarttime" prompt="开始时间"
                   style="width:30%;height:30px;padding:10px">
            --
            <input class="easyui-datebox" name="hpDisEndtime" prompt="结束时间"
                   style="width:30%;height:30px;padding:10px">
        </div>

        <div style="padding: 10px 60px;">
            <label style="margin: 0 10px">价格：</label>
            <input class="easyui-textbox" style="width: 25%" name="hpprice">
        </div>

        <div style="padding: 10px 50px;">
            <label style="margin: 0 10px">管理费：</label>
            <input class="easyui-textbox" style="width: 25%" name="hpcosts">
        </div>


        <div style="padding: 15px 50px;text-align: center">
            <a onclick="hostPowerSet()" href="javascript:void(0)" style="width: 20%" class="easyui-linkbutton">提交</a>
        </div>

    </form>
</div>

<%--条件搜索框--%>
<div id="tb" style="padding:2px 5px;">
    <form id="hostSearchForm" action="host/list.do">
        <input class="easyui-textbox" name="hname" prompt="姓名（可不填）" style="width:110px">
        <select class="easyui-combobox" name="status" panelHeight="auto" style="width:100px">
            <option value="">账号禁用</option>
            <option value="0">禁用</option>
            <option value="1">正常</option>
        </select>
        <select name="strong" class="easyui-combobox" panelHeight="auto" style="width:110px">
            <option value="">权重排序</option>
            <option value="desc">权重降序</option>
            <option value="asc">权重升序</option>

        </select>
        <select name="ordernumber" class="easyui-combobox" panelHeight="auto" style="width:110px">
            <option value="">订单量排序</option>
            <option value="desc">订单量降序</option>
            <option value="asc">订单量升序</option>

        </select>
        <select name="hpstar" class="easyui-combobox" panelHeight="auto" style="width:100px">
            <option value="">星推荐</option>
            <option value="0">否</option>
            <option value="1">是</option>

        </select>
        <select class="easyui-combobox" name="hpdiscount" panelHeight="auto" style="width:100px">
            <option value="">折扣</option>
            <option value="9">9折</option>
            <option value="8">8折</option>
            <option value="7">7折</option>
            <option value="6">6折</option>
            <option value="5">5折</option>
        </select>
        <a href="javascript:void(0)" onclick="searchHost()" class="easyui-linkbutton" iconCls="icon-search">搜索</a>
    </form>
</div>


<%--linkenbutton--%>
<div id="tt" style="padding:5px 0;">
    <a id="hostAdd" onclick="addHost()" href="javascript:void(0)" class="easyui-linkbutton"
       data-options="iconCls:'icon-add'">添加</a>
    <a id="delHost" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">删除</a>
    <a id="hostPower" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-tip'">权限设置</a>
    <a id="status" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-clear'">禁用启用账号</a>
</div>

<table id="dataTabs" style="height:500px"></table>

</body>

<script type="text/javascript">
    $(function () {
        $('#dataTabs').datagrid({
            url: 'host/list.do',
            fit: true,
            fitColumns: true,
            pagination: true,//分页条
            checkOnSelect: false,
            striped: true,
            toolbar: '#tt',//顶部工具栏
            header: '#tb',
            columns: [[
                {field: 'hid', checkbox: true},
                {
                    field: 'strong', title: '权重', width: 100, formatter: function (value, row, index) {
                        return '<input onchange="changeStrong(this.value,' + row.hid + ')" class="easyui-textbox" name="strong" value=' + value + ' style="width:100px">'
                    }
                },
                {field: 'hname', title: '姓名', width: 100},
                {field: 'hphone', title: '手机号', width: 100, align: 'right'},
                {field: 'starttime', title: '开通时间', width: 100},
                {field: 'hpprice', title: '价格', width: 100},
                {field: 'ordernumber', title: '订单量', width: 100},
                {field: 'hpdiscount', title: '折扣', width: 100},
                {
                    field: 'hpstar', title: '星推荐', width: 100, formatter: function (value, row, index) {

                        return value == 1 ? "是" : "<span style='color: red'>否</span>"
                    }
                },
                {
                    field: 'status', title: '账号状态', width: 100, formatter: function (value, row, index) {
                        return value == 1 ? "正常" : "<span style='color: red'>禁用</span>"
                    }
                }
            ]]
        });
    })

    function changeStrong(strong, hid) {

        $.post("host/changeStrong.do", {strong: strong, hid: hid}, function (data) {
            if (data) {

                $.messager.alert('温馨提示', '权重修改成功', 'info')
            }
        })
    }

    //条件搜索
    function searchHost() {
        var formData = $("#hostSearchForm").serializeJSON();

        $("#dataTabs").datagrid('load', formData);
    }

    //添加主持人
    function addHost() {
        $('#addWindow').window({
            closed: false
        });
    }

    function insertHost() {
        $('#hostForm').form('submit', {
            onSubmit: function () {
                var flag = $('#hostForm').form('validate');
                return flag;
            },
            success: function (data) {
                if (data) {
                    $('#addWindow').window({
                        closed: true
                    });
                    //清除表单
                    $("#hostForm").form('reset');
                    //刷新页面
                    $("#dataTabs").datagrid('reload');
                    $.messager.alert('添加主持人', '添加主持人成功', 'info')
                } else {
                    $('#addWindow').window({
                        closed: true
                    });
                    //清除表单
                    $("#hostForm").form('reset');
                    //刷新页面
                    $("#dataTabs").datagrid('reload');
                    $.messager.alert('添加主持人', '添加主持人失败', 'info')
                }
            }
        });
    }

    //禁用启用账号
    $("#status").click(function () {
        var check = $("#dataTabs").datagrid("getChecked");
        if (check.length == 0) {
            $.messager.alert('禁用启用账号', '至少选择一行', 'info')
        } else if (check.length > 1) {
            $.messager.alert('禁用启用账号', '一次只能选择一行', 'info')
        } else {
            var host = check[0];

            $.post("host/changeStatus.do", {hid: host.hid, status: host.status}, function (data) {
                if (data) {
                    //刷新页面
                    $("#dataTabs").datagrid('reload');
                    $.messager.alert('禁用启用账号', '修改主持人账号状态成功', 'info')
                } else {
                    //刷新页面
                    $("#dataTabs").datagrid('reload');
                    $.messager.alert('禁用启用账号', '修改主持人账号状态失败', 'info')
                }

            });

        }
    })
    //权限设置

    $("#hostPower").click(function () {

        var check = $("#dataTabs").datagrid("getChecked");

        if (check.length == 0) {
            $.messager.alert('禁用启用账号', '至少选择一行', 'info')
            return false
        }
        var hids = []

        var hnames = []
        $.each(check, function (index, host) {
            hids.push(host.hid);
            hnames.push(host.hname);
        })

        //设置权限设置的标题
        $("#hostPowerWindow").window({
            title: hnames.toString() + '权限设置',
            closed: false
        })

        //将id设置给权限设置表单隐藏域
        $("#hostid").val(hids.toString())

    })

    function hostPowerSet() {
        $("#hostPowerForm").form('submit', {
            onSubmit: function () {
                // var flag = $('#hostForm').form('validate');
                // return flag;
            },
            success: function (data) {

                if (data) {
                    $('#hostPowerWindow').window({
                        closed: true
                    });
                    //清除表单
                    $("#hostPowerForm").form('reset');
                    //刷新页面
                    $("#dataTabs").datagrid('reload');
                    $.messager.alert('权限设置', '权限操作成功', 'info')
                } else {
                    $('#hostPowerWindow').window({
                        closed: true
                    });
                    //清除表单
                    $("#hostPowerForm").form('reset');
                    //刷新页面
                    $("#dataTabs").datagrid('reload');
                    $.messager.alert('权限设置', '权限操作失败', 'info')
                }
            }
        })
    }

    //删除主持人
    $("#delHost").click(function () {
        //获取选择的id
        var check = $("#dataTabs").datagrid("getChecked");

        if (check.length == 0) {
            $.messager.alert("删除主持人", "至少选择一条数据", "info")
            return false
        }

        var hids = []

        $.each(check, function (index, host) {
            hids.push(host.hid)
        })

        $.messager.confirm('删除主持人', '你确定要删除选中的主持人吗?', function(r){
            if (r){
                $.get("host/deleteHost.do?hids=" + hids, function (data) {
                    if (data){
                        $("#dataTabs").datagrid('reload');
                        $.messager.alert('删除主持人', '删除成功', 'info')
                    }else {
                        $("#dataTabs").datagrid('reload');
                        $.messager.alert('删除主持人', '删除失败', 'info')
                    }
                })
            }
        });

    })

</script>
</html>
